#pragma once
#undef UNICODE

#include "Structures.h"
#include "InputMessage.h"
#include "DrawListMessage.h"

#include <winsock2.h>

#define DEFAULT_PORT "27015"

class Synch
{
private:
	int type;
	int numClients;
	InputMessage InMes;
	DrawListMessage DrLiMe;
private:
    WSADATA wsaData;
	struct addrinfo *result, *ptr, hints;
    int iResult;
    char recvbuf[MESSAGE_BUFF_LEN*5];
    char sendbuf[MESSAGE_BUFF_LEN*5];
	u_long NonBlocking;
	SOCKET MainSocket;
private:
	//server specific
	SOCKET clientSocket;
    int iSendResult;
private:
	void clearBuffer(char* buffer);
private:
	//server
	void ServerInit();
	void CheckForNewClient();
private:
	void ServerSend();
	bool ServerRecieve();
private:
	//client
	void ClientInit();
	bool ClientConnect();
	void ClientSend();
	bool ClientRecieve();
public:
	Synch();
	~Synch();
public:
	void Start(int ServerOrClient);
	void End();
public:
	/**server*/
	InputStruct Synchronize(LostVector<DrawStruct>* draw);
	/**client*/
	DrawListMessage* Synchronize(InputStruct);
};